package com.zkzx.driver.service;

import com.alibaba.fastjson.JSON;
import com.zkzx.common.company.model.CompanyDriverVO;
import com.zkzx.common.company.model.CompanyVO;
import com.zkzx.common.constants.NationalityEnum;
import com.zkzx.common.constants.SourceEnum;
import com.zkzx.common.constants.StatusEnum;
import com.zkzx.common.constants.YesNOEnum;
import com.zkzx.common.driver.command.DriverCommand;
import com.zkzx.common.driver.constants.DriverAlidityEnum;
import com.zkzx.common.driver.constants.DriverStatusEnum;
import com.zkzx.common.driver.model.DriverQualificationVO;
import com.zkzx.common.driver.param.DriverInvitationParam;
import com.zkzx.common.driver.param.DriverThreeElementsParam;
import com.zkzx.common.driver.model.DriverListVO;
import com.zkzx.common.driver.model.DriverVO;
import com.zkzx.common.driver.param.DriverFilterParam;
import com.zkzx.common.driver.vo.DriverAlidityVO;
import com.zkzx.common.driver.vo.DriverNationVO;
import com.zkzx.common.driver.vo.DriverStatusVO;
import com.zkzx.common.exception.BaseException;
import com.zkzx.common.exception.ExceptionEnum;
import com.zkzx.common.global.Global;
import com.zkzx.common.sms.constants.SmsTemplateEnum;
import com.zkzx.common.vo.PageResult;
import com.zkzx.common.vo.RequestFilterParams;
import com.zkzx.common.vo.StatusVO;
import com.zkzx.driver.client.CompanyDriverClient;
import com.zkzx.driver.client.WhAdaptorClient;
import com.zkzx.driver.mapper.DriverMapper;
import com.zkzx.driver.mapper.entity.Driver;
import com.zkzx.driver.mapper.entity.DriverExample;
import com.zkzx.util.config.PrimaryMarkUtil;
import com.zkzx.util.data.HideDataUtil;
import com.zkzx.util.date.DateUtil;
import com.zkzx.util.json.JSONResultUtil;
import com.zkzx.util.sql.SQLUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import javax.ws.rs.HttpMethod;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 北京中科智兴物联科技有限公司 @版权所有
 *
 * @Author: zhaoyihe@zkraising.com
 * @Date: 2021/05/07/19:14
 * @Description:
 */
@Slf4j
@Service
public class DriverService {

    @Resource
    private DriverMapper driverMapper;
    @Autowired
    private DriverBankService driverBankService;
    @Autowired
    private DriverLicenseService driverLicenseService;
    @Autowired
    private DriverQualificationService driverQualificationService;
    @Autowired
    private CompanyDriverClient companyDriverClient;
    @Autowired
    private WhAdaptorClient whAdaptorClient;

    /**
     * 分页查询司机数据
     * @param filterParamJson 查询条件
     * @param paramsJson 分页参数
     * @return 司机分页数据
     */
    public PageResult<DriverListVO> find(String filterParamJson, String paramsJson) {

        DriverFilterParam filterParam = (DriverFilterParam) JSONResultUtil.toObject(filterParamJson, DriverFilterParam.class);
        RequestFilterParams params = (RequestFilterParams) JSONResultUtil.toObject(paramsJson, RequestFilterParams.class);

        DriverExample driverExample= buildDriverExample(filterParam);
        Long size = driverMapper.countByExample(driverExample);
        int totalNum = size.intValue();
        if (size <= Global.ZERO){
            return new PageResult<>(params.getPage(),params.getPerPage(), Collections.emptyList(), Global.ZERO);
        }
        List<DriverListVO> list = getDriversByOperation(driverExample, params);

        return new PageResult<>(params.getPage(),params.getPerPage(),list, totalNum);
    }

    /**
     * 封装查询条件
     * @param filterParam 查询参数信息
     * @return 查询条件
     */
    private DriverExample buildDriverExample( DriverFilterParam filterParam ){
        DriverExample driverExample= new DriverExample();
        DriverExample.Criteria criteria = driverExample.createCriteria();
        if(!StringUtils.isEmpty(filterParam.getCid())){
            criteria.andCidLike(SQLUtil.valueBuildLike(filterParam.getCid()));
        }
        if(!StringUtils.isEmpty(filterParam.getName())){
            criteria.andNameLike(SQLUtil.valueBuildLike(filterParam.getName()));
        }
        if(!StringUtils.isEmpty(filterParam.getIdentification())){
            criteria.andIdentificationEqualTo(filterParam.getIdentification());
        }
        if(!StringUtils.isEmpty(filterParam.getRelationNumber())){
            criteria.andRelationnumberEqualTo(filterParam.getRelationNumber());
        }
        if(!StringUtils.isEmpty(filterParam.getStatus())){
            criteria.andStatusEqualTo(filterParam.getStatus());
        }
        if(CollectionUtils.isNotEmpty(filterParam.getStatusList())){
            criteria.andStatusIn(filterParam.getStatusList());
        }

        return driverExample;
    }


    /**
     * 根据id获取司机详情信息
     * @param id 司机id
     * @return 司机详情信息
     */
    public DriverVO getById(Integer id,Integer companyId) {
        Driver driver = driverMapper.selectByPrimaryKey(id);
        if(Objects.isNull(driver)){
            return null;
        }

        DriverVO driverVO = new DriverVO();
        driverVO.setId(driver.getId());
        driverVO.setCid(driver.getCid());
        driverVO.setThreeId(driver.getThreeid());
        driverVO.setName(driver.getName());
        driverVO.setIdentification(driver.getIdentification());
        driverVO.setDriverBank(driverBankService.findVOByDriverId(driver.getId()));
        driverVO.setRemarks(driver.getRemarks());
        driverVO.setStatusVO(StatusVO.builder()
                .value(DriverStatusEnum.valueOf(driver.getStatus()).name())
                .description(DriverStatusEnum.valueOf(driver.getStatus()).getDescription())
                .belong(belong(driver.getSource(),driver.getStatus(),HttpMethod.GET,driver.getCreatecompany(),companyId))
                .build());
        driverVO.setSource(driver.getSource());
        driverVO.setCompanyId(companyId);
        driverVO.setCreateCompany(driver.getCreatecompany());
        if (companyId.equals(Global.ZERO) ||
                StatusEnum.PRIVATE_DETAIL == belong(driver.getSource(),driver.getStatus(),HttpMethod.GET,driver.getCreatecompany(),companyId)){
            driverVO.setDriverAlidityVO(DriverAlidityVO.builder()
                    .value(StringUtils.isEmpty(driver.getIdentificationstatus()) ? null : DriverAlidityEnum.valueOf(driver.getIdentificationstatus()).name())
                    .description(StringUtils.isEmpty(driver.getIdentificationstatus()) ? null : DriverAlidityEnum.valueOf(driver.getIdentificationstatus()).getDescription())
                    .build());
            driverVO.setIdentificationStartTime(driver.getIdentificationstarttime());
            driverVO.setIdentificationEndTime(driver.getIdentificationendtime());
            driverVO.setIdentificationFrontPic(driver.getIdentificationfrontpic());
            driverVO.setIdentificationBackPic(driver.getIdentificationbackpic());
            driverVO.setRegionId(driver.getRegionid());
            driverVO.setRegionInfo(driver.getRegioninfo());
            driverVO.setIdentificationAddress(driver.getIdentificationaddress());
            driverVO.setDriverPic(driver.getDriverpic());
            driverVO.setCreateTime(driver.getCreatetime());
            driverVO.setLastModifiedTime(driver.getLastmodifiedtime());
            driverVO.setCreateUser(driver.getCreateuser());
            driverVO.setLastModifiedUser(driver.getLastmodifieduser());
            driverVO.setSource(driver.getSource());
            driverVO.setDriverLicense(driverLicenseService.findVOByDriverId(driver.getId()));
            driverVO.setDriverQualification(driverQualificationService.findVOByDriverId(driver.getId()));

            driverVO.setDriverNationVO(DriverNationVO.builder()
                    .value(NationalityEnum.getName(driver.getNation()))
                    .description(NationalityEnum.getValue(driver.getNation()))
                    .build());
            driverVO.setProvince(driver.getProvince());
            driverVO.setCity(driver.getCity());
            driverVO.setCounty(driver.getCounty());
        }

            List<CompanyDriverVO>  companyDrivers = companyDriverClient.getByDriverIdAndCompanyId(id, companyId);
            if(CollectionUtils.isNotEmpty(companyDrivers)){
                driverVO.setMobile(companyDrivers.get(Global.ZERO).getMobile());

                driverVO.setTruckId(companyDrivers.get(Global.ZERO).getTruckId());
            }


        return driverVO;
    }


    /**
     * 新增司机信息
     * @param command 入参
     * @param userId 用户id
     */
    public StatusVO add(DriverCommand command, int userId){
        DriverExample driverExample = new DriverExample();
        DriverExample.Criteria criteria = driverExample.createCriteria();
        criteria.andNameEqualTo(command.getName());
        criteria.andIdentificationEqualTo(command.getIdentification());
        Optional<Driver> drivers = driverMapper.selectByExample(driverExample).stream().findFirst();

        if(drivers.isPresent()){

            // 如果司机存在 需要将司机关系企业数进行累计 同时创建关联关系
            Driver driver = drivers.get();
            //防止重复录入中间表
            List<CompanyDriverVO> companyDriverVOS = companyDriverClient.getByDriverIdAndCompanyId(driver.getId(), command.getCompanyId());
            if (CollectionUtils.isNotEmpty(companyDriverVOS)){
                throw new BaseException(ExceptionEnum.DRIVER_CODD_ERROR.getCode(),ExceptionEnum.DRIVER_CODD_ERROR.getMsg());
            }

            Integer relationNumber = Integer.parseInt(driver.getRelationnumber()) + Global.ONE;
            driver.setRelationnumber(relationNumber.toString());
            driverMapper.updateByPrimaryKeySelective(driver);

            return StatusVO.builder().id(driver.getId()).value(DriverStatusEnum.valueOf(driver.getStatus()).name())
                    .description(DriverStatusEnum.valueOf(driver.getStatus()).getDescription())
                    .belong(belong(driver.getSource(),driver.getStatus(),HttpMethod.POST,driver.getCreatecompany(),command.getCompanyId()))
                    .build();
        }

        long count = driverMapper.countByExample(driverExample);
        if(count > Global.ZERO){
            throw new BaseException(ExceptionEnum.DRIVER_CODD_ERROR.getCode(), ExceptionEnum.DRIVER_CODD_ERROR.getMsg());
        }

        Driver driver = new Driver();
        // 需要随机生成登录码 setaqy + 年份两位+月+日+随机四位数
        driver.setCid(PrimaryMarkUtil.getSJMark());
        driver.setName(command.getName());
        driver.setIdentification(command.getIdentification());
        driver.setNation(command.getNation());
        driver.setIdentificationstatus(command.getIdentificationStatus());
        driver.setIdentificationstarttime(command.getIdentificationStartTime());
        driver.setIdentificationendtime(command.getIdentificationEndTime());
        driver.setRegionid(command.getRegionId());
        driver.setRegioninfo(command.getRegionInfo());
        driver.setIdentificationaddress(command.getIdentificationAddress());
        driver.setIdentificationfrontpic(command.getIdentificationFrontPic());
        driver.setIdentificationbackpic(command.getIdentificationBackPic());
        driver.setDriverpic(command.getDriverPic());
        driver.setSource(StringUtils.isEmpty(command.getSource()) ? SourceEnum.SHARE.name(): command.getSource());
        driver.setStatus(DriverStatusEnum.NO_SUBMIT.name());
        driver.setCreatetime(new Date());
        driver.setLastmodifiedtime(new Date());
        driver.setCreateuser(userId);
        driver.setLastmodifieduser(userId);
        driver.setRelationnumber(Global.ONE.toString());
        driver.setRemarks(command.getRemarks());
        driver.setProvince(command.getProvince());
        driver.setCity(command.getCity());
        driver.setCounty(command.getCounty());
        driver.setCreatecompany(command.getCompanyId());
        driverMapper.insert(driver);
        Optional<Driver> first = driverMapper.selectByExample(driverExample).stream().findFirst();
        Integer id = 0;
        if(first.isPresent()){
            id= first.get().getId();
        }

        DriverCommand whDriverCommand=null;
        try{
            whDriverCommand = whAdaptorClient.getDriver(id, command.getName(), command.getIdentification());
        }catch (Exception e){
            driverMapper.deleteByPrimaryKey(id);

            throw new BaseException(ExceptionEnum.WH_DATA_ERROR.getCode(), ExceptionEnum.WH_DATA_ERROR.getMsg());
        }
        if(Objects.isNull(whDriverCommand)){
            return StatusVO.builder().id(id).value(DriverStatusEnum.valueOf(driver.getStatus()).name())
                    .description(DriverStatusEnum.valueOf(driver.getStatus()).getDescription())
                    .belong(belong(driver.getSource(),driver.getStatus(),HttpMethod.POST,driver.getCreatecompany(),command.getCompanyId()))
                    .build();
        }
        driverBankService.insert(command,id);
        driverLicenseService.insert(command,id);
        driverQualificationService.insert(command,id);
        insertCompanyDriver(command,driver,id);
        //这是从网货查回来的，全表更新
        whDriverCommand.setCompanyId(Global.ZERO);
        this.update(whDriverCommand,id,userId);
        String source = Optional.ofNullable(whDriverCommand.getSource()).orElse(driver.getSource());
        return StatusVO.builder().id(id).value(DriverStatusEnum.valueOf(whDriverCommand.getStatus()).name())
                .description(DriverStatusEnum.valueOf(whDriverCommand.getStatus()).getDescription())
                .belong(belong(source,whDriverCommand.getStatus(),HttpMethod.POST,driver.getCreatecompany(),command.getCompanyId()))
                .build();
    }

    /**
     * 更新司机信息
     * @param command 入参
     * @param id 司机id
     * @param userId 登录人id
     */
    public void update(DriverCommand command, Integer id, int userId) {
        //更新司机,不更新司机ID，不更新id
        Driver driver = new Driver();
        driver.setId(id);
        driver.setThreeid(command.getThreeId());
        driver.setNation(command.getNation());
        driver.setIdentificationstatus(command.getIdentificationStatus());
        driver.setIdentificationstarttime(command.getIdentificationStartTime());
        driver.setIdentificationendtime(command.getIdentificationEndTime());
        driver.setRegionid(command.getRegionId());
        driver.setRegioninfo(command.getRegionInfo());
        driver.setIdentificationaddress(command.getIdentificationAddress());
        driver.setIdentificationfrontpic(command.getIdentificationFrontPic());
        driver.setIdentificationbackpic(command.getIdentificationBackPic());
        driver.setDriverpic(command.getDriverPic());
        driver.setStatus(StringUtils.isEmpty(command.getStatus()) ? DriverStatusEnum.NO_SUBMIT.name(): command.getStatus());
        driver.setLastmodifiedtime(new Date());
        driver.setLastmodifieduser(userId);
        driver.setRemarks(command.getRemarks());
        driver.setProvince(command.getProvince());
        driver.setCity(command.getCity());
        driver.setCounty(command.getCounty());
        driver.setSource(command.getSource());

        DriverExample driverExample = new DriverExample();
        DriverExample.Criteria criteria = driverExample.createCriteria();
        criteria.andIdEqualTo(id);
        driverMapper.updateByExampleSelective(driver,driverExample);
        driverBankService.insertOrUpdateBank(command,id);
        driverLicenseService.insertOrUpdateLicense(command,id);
        driverQualificationService.insertOrUpdateQualification(command,id);
        //更新中间表

        updateCompanyDriver(command,driver);
    }


    /**
     * 获取验证码
     * @param userId 用户id
     * @param id 司机id
     * @param companyId 公司id
     * @return 司机状态
     */
    public DriverStatusVO  verification(Integer id,Integer userId,Integer companyId) {
        DriverVO driverVO = this.getById(id, companyId);
        DriverThreeElementsParam dto = new DriverThreeElementsParam();
        dto.setTelephone(driverVO.getMobile());
        dto.setName(driverVO.getName());
        dto.setIdCard(driverVO.getIdentification());
        DriverCommand driverCommand = whAdaptorClient.getIdentityKey(id, dto);
        driverCommand.setCompanyId(companyId);
        this.update(driverCommand,id,userId);
        return DriverStatusVO.builder().id(id).value(DriverStatusEnum.valueOf(driverCommand.getStatus()).name())
                .description(DriverStatusEnum.valueOf(driverCommand.getStatus()).getDescription()).build();
    }

    /**
     * 提交
     * @param id 司机id
     * @param captcha 用户id
     * @param userId 用户id
     * @param companyId 公司id
     * @return 司机状态
     */

    public DriverStatusVO submit(Integer id,String captcha,Integer userId,Integer companyId)  {
        DriverVO driverVO = this.getById(id, companyId);
        //再查一遍
        DriverCommand driverCommand = whAdaptorClient.getDriver(id, driverVO.getName(), driverVO.getIdentification());
        if (DriverStatusEnum.NO_SUBMIT.name().equals(driverCommand.getStatus())){
            driverCommand.setStatus(DriverStatusEnum.ACTIVATED_WAIT.name());
            if (!StringUtils.isEmpty(captcha)){
                //Remarks不能为空，空的话说明3key还没获取到
                CompanyVO companyVO = companyDriverClient.getById(companyId);
                driverVO.setCompanyThreeId(companyVO.getThreeId());
                driverCommand = whAdaptorClient.add(id, driverVO, captcha, driverVO.getRemarks());
            }
        }
        driverCommand.setCompanyId(companyId);
        this.update(driverCommand,id,userId);
        return DriverStatusVO.builder().id(id).value(DriverStatusEnum.valueOf(driverCommand.getStatus()).name())
                .description(DriverStatusEnum.valueOf(driverCommand.getStatus()).getDescription()).build();
    }

    /**
     * 邀请签约
     * @param id 司机id
     * @param endTime 合同有效时间
     * @param userId 用户id
     * @param companyId 公司id
     * @return 司机状态
     */

    public DriverStatusVO signContract(Integer id,String endTime,Integer userId,Integer companyId){
        DriverVO driverVO = this.getById(id, companyId);
        DriverInvitationParam dto = new DriverInvitationParam();
        dto.setDriverId(driverVO.getThreeId());
        dto.setTelephone(driverVO.getMobile());
        dto.setEndTime(endTime);
        DriverCommand driverCommand = whAdaptorClient.getContractSign(id, dto);
        driverCommand.setCompanyId(companyId);
        this.update(driverCommand,id,userId);

        return DriverStatusVO.builder().id(id).value(DriverStatusEnum.valueOf(driverCommand.getStatus()).name())
                .description(DriverStatusEnum.valueOf(driverCommand.getStatus()).getDescription()).build();
    }


    /**
     * 更新司机网货对接状态
     * @param vo 企业司机信息
     */
    public void updateToWh(DriverListVO vo){
        DriverVO driverVO = this.getById(vo.getId(), Global.ZERO);
        DriverCommand driverCommand = new DriverCommand();
        driverCommand.setId(vo.getId());
        driverCommand.setStatus(vo.getStatus().getValue());
        driverCommand = whAdaptorClient.getStatus(vo.getId(),driverVO.getThreeId());
        //查询司机审核状态
        if (DriverStatusEnum.VERIFY_SUCCESS.name().equals(driverCommand.getStatus())){
            driverCommand = whAdaptorClient.getDriver(vo.getId(),driverVO.getName(), driverVO.getIdentification());
        }
        driverCommand.setCompanyId(Global.ZERO);
        this.update(driverCommand,vo.getId(),Global.ZERO);
        //司机发短信的三种状态
        this.sendSmsStatus(driverCommand,driverVO);
    }

    /**
     * 更新司机合同网货对接状态
     * @param vo 企业司机信息
     */
    public void updateContractToWh(DriverListVO vo){
        DriverVO driverVO = this.getById(vo.getId(), Global.ZERO);

        DriverCommand driverCommand = new DriverCommand();
        driverCommand.setId(vo.getId());
        driverCommand.setStatus(vo.getStatus().getValue());

        driverCommand = whAdaptorClient.getContractStatus(vo.getId(), driverVO.getDriverQualification().getContractNum(),driverVO.getMobile());

        if (DriverStatusEnum.VERIFY_SUCCESS.name().equals(driverCommand.getStatus())){
            driverCommand = whAdaptorClient.getDriver(vo.getId(), driverVO.getName(), driverVO.getIdentification());
            if (Objects.nonNull(driverCommand.getDriverQualification())){
                DriverQualificationVO driverQualification = driverCommand.getDriverQualification();
                driverQualification.setContractStatus(YesNOEnum.YES.name());
            }
        }
        driverCommand.setCompanyId(Global.ZERO);
        this.update(driverCommand,vo.getId(),Global.ZERO);
        //司机发短信的三种状态
        this.sendSmsStatus(driverCommand,driverVO);
    }



    /**
     * 更新企业司机中间表
     * @param driver 司机信息
     * @param command 司机入参
     */

    public void updateCompanyDriver(DriverCommand command,Driver driver){
        CompanyDriverVO companyDriverVO = new CompanyDriverVO();
        companyDriverVO.setMobile(command.getMobile());
        companyDriverVO.setDriverName(command.getName());
        companyDriverVO.setDriverStatus(driver.getStatus());
        companyDriverVO.setDriverSource(driver.getSource());
        companyDriverVO.setDriverId(driver.getId());
        companyDriverVO.setTruckId(command.getTruckId());
        companyDriverVO.setCompanyId(command.getCompanyId());
        companyDriverClient.update(companyDriverVO);
    }

    public void insertCompanyDriver(DriverCommand command,Driver driver,Integer id){
        CompanyDriverVO companyDriverVO = new CompanyDriverVO();
        companyDriverVO.setCompanyId(command.getCompanyId());
        companyDriverVO.setDriverId(id);
        companyDriverVO.setMobile(command.getMobile());
        companyDriverVO.setDriverName(command.getName());
        companyDriverVO.setDriverStatus(driver.getStatus());
        companyDriverVO.setDriverSource(driver.getSource());
        companyDriverVO.setTruckId(command.getTruckId());
        companyDriverClient.add(companyDriverVO);
    }

    public List<DriverListVO> getDriversByCompany(List<CompanyDriverVO> companyDriverVOS) {

        return companyDriverVOS.stream().map(companyDriverTruckVO -> {
            Driver driver = driverMapper.selectByPrimaryKey(companyDriverTruckVO.getDriverId());
            return buildDriverListVO(companyDriverTruckVO.getDriverId(),driver);
        }).collect(Collectors.toList());

    }

    public List<DriverListVO> getDriversByOperation(DriverExample driverExample,RequestFilterParams params){

        driverExample.setOrderByClause(params.getField().concat(" ").concat(params.getOrder()));
        driverExample.page(params.getPage() - Global.ONE , params.getPerPage());
        List<Driver> drivers = driverMapper.selectByExample(driverExample);
        return drivers.stream().map(driver ->
                buildDriverListVO(driver.getId(),driver)
        ).collect(Collectors.toList());

    }

    /**
     * 封装司机列表信息
     * @param id 司机id
     * @param driver 司机信息
     * @return 司机列表信息
     */
    private DriverListVO buildDriverListVO(int id ,Driver driver){
        return  DriverListVO.builder()
                .id(id)
                .threeId(driver.getThreeid())
                .cid(driver.getCid())
                .name(driver.getName())
                .identification(HideDataUtil.getHideData(driver.getIdentification()))
                .driverBank(driverBankService.findVOByDriverIdHide(driver.getId()))
                .relationNumber(driver.getRelationnumber())
                .createTime(DateUtil.convertDateToString(driver.getCreatetime()))
                .source(driver.getSource())
                .status(StatusVO.builder()
                        .value(DriverStatusEnum.valueOf(driver.getStatus()).name())
                        .description(DriverStatusEnum.valueOf(driver.getStatus()).getDescription())
                        .build())
                .build();
    }



    /**
     * 判断归属信息
     * @param source 来源
     * @param status 当前状态
     * @param createCompany 创建企业
     * @param company 当前企业
     * @return true 属于当前企业 false 不属于当前企业
     */
    private StatusEnum belong(String source, String status,  String method,Integer createCompany, Integer company){
        // 判断来源是否属于网货
        if(SourceEnum.SHARE.name().equals(source)){
            // 审核中 或者 审核失败  等 跳转失败提示页面
            if(DriverStatusEnum.APPROVE_ING.name().equals(status) || DriverStatusEnum.APPROVE_FAIL.name().equals(status)){
                return StatusEnum.REASON;
            }

            // 审核成功 跳转详情页面
            return StatusEnum.PUBLIC_DETAIL;

        }

        // 判断自建是否是当前企业建立

        // 如果信息不存在 跳转录入页面
        if(DriverStatusEnum.NO_SUBMIT.name().equals(status)  &&  HttpMethod.POST.equals(method) &&createCompany.equals(company)){
            return StatusEnum.INPUT;
        }

        // 未提交  审核中  审核失败 审核 成功 但是 当前登录企业  = 数据初始企业
        if (createCompany.equals(company)){
            return StatusEnum.PRIVATE_DETAIL;
        }

        // 存在 跳转详情页面
        return StatusEnum.PUBLIC_DETAIL;
    }

    /**
     * 司机应该发短信的三种状态
     * @param driverCommand
     * @param driverVO
     */
    public void sendSmsStatus(DriverCommand driverCommand,DriverVO driverVO){
        //司机的三种状态
        if (!DriverStatusEnum.VERIFY_SUCCESS.name().equals(driverCommand.getStatus())
                && !DriverStatusEnum.APPROVE_FAIL.name().equals(driverCommand.getStatus())
                && !DriverStatusEnum.BANK_FAIL.name().equals(driverCommand.getStatus())){
           return;
        }
        CompanyVO companyVO = companyDriverClient.getById(driverVO.getCreateCompany());
        this.sendDriverSms(driverCommand.getStatus(),companyVO.getMemberMobile(),companyVO.getName(),driverVO.getName());
    }


    /**
     * 司机审核短信通知
     * @param status  司机状态
     * @param mobile 公司联系人手机号
     * @param companyName 公司名称
     * @param driverName 车牌号
     */
    public void sendDriverSms(String status,String mobile,String companyName,String driverName){
        Map<String, String> parameterMap = new HashMap<>();
        //审核成功、审核失败、绑卡失败传参一致
        parameterMap.put(SmsTemplateEnum.DRIVER_EXAMINE_SUCCESS.getParameterArr()[Global.ZERO],companyName);
        parameterMap.put(SmsTemplateEnum.DRIVER_EXAMINE_SUCCESS.getParameterArr()[Global.ONE],driverName);
        if (DriverStatusEnum.VERIFY_SUCCESS.name().equals(status)){
            //已验证
            companyDriverClient.sendSms(mobile, SmsTemplateEnum.DRIVER_EXAMINE_SUCCESS.getTemplate(), JSON.toJSONString(parameterMap));
        }else if (DriverStatusEnum.APPROVE_FAIL.name().equals(status)){
            //审核驳回
            companyDriverClient.sendSms(mobile, SmsTemplateEnum.DRIVER_EXAMINE_FAIL.getTemplate(), JSON.toJSONString(parameterMap));
        }else if (DriverStatusEnum.BANK_FAIL.name().equals(status)){
            //绑卡失败
            companyDriverClient.sendSms(mobile, SmsTemplateEnum.DRIVER_CARD_FAIL.getTemplate(), JSON.toJSONString(parameterMap));
        }
    }
}
